<?php    
    function loaiDauTV($str) {
		$chars = array(
			'a'		=>    array('ấ','ầ','ẩ','ẫ','ậ','Ấ','Ầ','Ẩ','Ẫ','Ậ','ắ','ằ','ẳ','ẵ','ặ','Ắ','Ằ','Ẳ','Ẵ','Ặ','á','à','ả','ã','ạ','â','ă','Á','À','Ả','Ã','Ạ','Â','Ă'),
			'e'		=>    array('ế','ề','ể','ễ','ệ','Ế','Ề','Ể','Ễ','Ệ','é','è','ẻ','ẽ','ẹ','ê','É','È','Ẻ','Ẽ','Ẹ','Ê'),
			'i'		=>    array('í','ì','ỉ','ĩ','ị','Í','Ì','Ỉ','Ĩ','Ị'),
			'o'		=>    array('ố','ồ','ổ','ỗ','ộ','Ố','Ồ','Ổ','Ô','Ộ','ớ','ờ','ở','ỡ','ợ','Ớ','Ờ','Ở','Ỡ','Ợ','ó','ò','ỏ','õ','ọ','ô','ơ','Ó','Ò','Ỏ','Õ','Ọ','Ô','Ơ'),
			'u'		=>    array('ứ','ừ','ử','ữ','ự','Ứ','Ừ','Ử','Ữ','Ự','ú','ù','ủ','ũ','ụ','ư','Ú','Ù','Ủ','Ũ','Ụ','Ư'),
			'y'		=>    array('ý','ỳ','ỷ','ỹ','ỵ','Ý','Ỳ','Ỷ','Ỹ','Ỵ'),
			'd'		=>    array('đ','Đ'),
		);
    	foreach ($chars as $key => $arr) 
    		foreach ($arr as $val)
    			$str = str_replace($val,$key,$str);
    		$str = strtolower($str);
    		
    		return $str;
	}
    
	function tachChuoi($str){
		$str = loaiDauTV($str);	
		$symbolsRemove = array('/','\\','\'','"',',','.','<','>','?',';',':','[',']','{','}','|','=','+','-','_',')','(','*','&','^','%','$','#','@','!','~','`');
        for ($i = 0; $i < sizeof($symbolsRemove); $i++){
			$str = str_replace($symbolsRemove[$i],' ',$str);
		}
		
		//Xoá khoảng trắng (>=2), tab, xuống dòng
		$str = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $str);
		
		 //Tách chuỗi thành mảng bởi dấu cách
		$arrKw = explode(' ',$str);
		//$arrKw = split(' ',$str);
		 //Tạo mảng kết quả chứa keyword
		$kwResult = array();
		
		//Duyệt mảng và đưa vào các từ khoá hợp lệ
		foreach($arrKw as $arr){
			if($arr!=''){
				array_push($kwResult,$arr);
			}
		}
		return $kwResult;
	} 
    function isNumber($num){
        $reg="/^[0-9]{1,2}$/";
        if(preg_match($reg,$num)){
    		return 1;
    	}else{
    		return 0;
    	}
    }
?>